<?php
include 'checkLogin.php';

@$addType = $_REQUEST['addType'];

@$name = $_REQUEST['name'];
@$stockPrice = $_REQUEST['stockPrice'];
@$sellPrice = $_REQUEST['sellPrice'];
@$sellStatus = $_REQUEST['sellStatus'];
@$basicStatus = $_REQUEST['basicStatus'];
@$stock = $_REQUEST['stock'];
@$typeId = $_REQUEST['typeId'];
@$img = $_FILES['file'];
move_uploaded_file($img['tmp_name'],'img/'.$img['name']);

@$age = $_REQUEST['age'];
@$sex = $_REQUEST['sex'];
@$idCard = $_REQUEST['idCard'];
@$phone = $_REQUEST['phone'];
@$location = $_REQUEST['location'];
@$roleId = $_REQUEST['roleId'];
include 'db/li.php';

if($addType == "goods"){
	if(empty($name)||empty($stockPrice)||empty($sellPrice)||empty($sellStatus)||empty($basicStatus)||empty($stock)||empty($typeId)){
		$mes = '都必须填写';
		include 'addGoodsType.php';
		die;
	}
	
	@$flog = dbInsert('insert into goods(imgUrl,name,stockPrice,sellPrice,sellStatus,basicStatus,stock,typeId) values(:img,:name,:stockPrice,:sellPrice,:sellStatus,:basicStatus,:stock,:typeId)',
			array('img'=>$img['name'],'name'=>$name,'stockPrice'=>$stockPrice,'sellPrice'=>$sellPrice,'sellStatus'=>$sellStatus,'basicStatus'=>$basicStatus,'stock'=>$stock,'typeId'=>$typeId));
	
	if(!$flog){
		$mes = '添加商品失败';
		include 'addGoodsType.php';
		die;
	}
	header('Refresh:0;url=goodsList.php');
	die;
}

if($addType == "type"){
	if(empty($name)){
		$mes = '都必须填写';
		include 'addGoodsType.php';
		die;
	}
	
	@$flog = dbInsert('insert into type(name) values(:name)',array('name'=>$name));
	
	if(!$flog){
		$mes = '添加商品类型失败';
		include 'addGoodsType.php';
		die;
	}
	header('Refresh:0;url=typeList.php');
	die;
	
}
if($addType == "worker"){
	@$flog = dbInsert('insert into worker(imgUrl,name,age,sex,idCard,phone,location,roleId) values(:imgUrl,:name,:age,:sex,:idCard,:phone,:location,:roleId)',
			array('imgUrl'=>$img['name'],'name'=>$name,'age'=>$age,'sex'=>$sex,'idCard'=>$idCard,'phone'=>$phone,'location'=>$location,'roleId'=>$roleId));
	
	if(!$flog){
		$mes = '添加职员失败';
		include 'addGoodsType.php';
		die;
	}
	header('Refresh:0;url=workerList.php?type=worker');
	die;
}

if($addType == "role"){
	@$flog = dbInsert('insert into role(name) values(:name)',array('name'=>$name));
	
	if(!$flog){
		$mes = '添加职员失败';
		include 'addGoodsType.php';
		die;
	}
	header('Refresh:0;url=workerList.php?type=role');
	die;
}














